<?php
/**
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/
 * @license    GNU/GPL
*/

// no direct access

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the HelloWorld Component
 *
 * @package    HelloWorld
 */

class calendarViewcalendar extends JView
{
    function display($tpl = null)
    {
		global $option, $mainframe;
		/*
		if($this->getLayout() == 'detail') {
			//var_dump('view, display');
			$this->displayDetail($tpl);
			return;
		}
		*/
		//var_dump('view');
        $model = $this->getModel();
		//var_dump($model);
		$model->_setBuild('Calendar');
        $items =  $this->get('Data');
		//var_dump($items);
		//$daysInMonth =& $model->diary2($items);
		$date_obj = new stdclass();
		$date_obj->year = JRequest::getVar('year');
		$date_obj->month = JRequest::getVar('month');
		$date_obj->day = JRequest::getVar('day');
		$cal_obj =& $model->diary2($items, $date_obj);
		//$html = $this->table($daysInMonth);
		//var_dump($daysInMonth);
		$cal_obj->uri->setFragments('year','month','day');
		$this->assignRef('cal_uri', $cal_obj->uri);
		$this->assignRef('cal_text', $cal_obj->textual);
		$this->assignRef('daysInMonth', $cal_obj->daysInMonth);
		$this->assignRef('items', $items);
	//	$this->assignRef('html', $html);
		
		// insert <link rel="stylesheet" href="/rc3/media/system/css/modal.css" type="text/css" />
		JHTML::stylesheet('modal.css');
		//JHTML::script('mootools.js','',true);
		JHTML::_('behavior.mootools');
		JHTML::script('modal.js');
		
		//var_dump('pre-display');
        parent::display($tpl);
    }
	
	function display_api($tpl = null)
    {
		global $option, $mainframe;
		/*
		if($this->getLayout() == 'detail') {
			//var_dump('view, display');
			$this->displayDetail($tpl);
			return;
		}
		*/
	/*	
        $model = $this->getModel();
		//var_dump($model);
		$model->_setBuild('Calendar');
        $items =  $this->get('Data');
		//var_dump($items);
		$daysInMonth =& $model->diary2($items);
		//$html = $this->table($daysInMonth);
		//var_dump($daysInMonth);
		$this->assignRef('daysInMonth', $daysInMonth);
		$this->assignRef('items', $items);
	//	$this->assignRef('html', $html);
		*/
		
		// insert <link rel="stylesheet" href="/rc3/media/system/css/modal.css" type="text/css" />
		JHTML::stylesheet('modal.css');
		//JHTML::script('mootools.js','',true);
		JHTML::_('behavior.mootools');
		JHTML::script('modal.js');
		

        parent::display($tpl);
    }
	/*
	function displayDetail($tpl = null)
    {
		global $mainframe, $option;

		//jimport('joomla.html.pane');
		
		$db		=& JFactory::getDBO();
		$uri 	=& JFactory::getURI();
		$user 	=& JFactory::getUser();
		$model	=& $this->getModel();
		
//		$model->_setBuild('Detail');
//	    $items =  $this->get('Data');
		//var_dump($items);
		
	//	$daysInMonth =& $model->diary2($items);
		//$html = $this->table($daysInMonth);
		//var_dump($daysInMonth);
	//	$this->assignRef('daysInMonth', $daysInMonth);
	//	$this->assignRef('items', $items);
	//	$this->assignRef('html', $html);
		$this->assignRef('item', $item);
		// insert <link rel="stylesheet" href="/rc3/media/system/css/modal.css" type="text/css" />
		//JHTML::stylesheet('modal.css');

        parent::display($tpl);
    }
	*/
	function table(&$D){
	
		//while ($Day = $D->fetch()) {
		foreach($D as $Day) {
			if ($Day->isFirst()) {
				$html .=  "<tr>\n";
			}
		
			if ($Day->isEmpty()) {
				$html .= '<td width="50px">&nbsp;</td>\n';
			} else {
				$test = method_exists( $Day  , 'isSelected');
				//echo $test;
				
				if($Day->isSelected()){ //->isSelected()
					$html .='<div>here</div>';
					$html .='<td width="50px">\n\t<div>'.$Day->thisDay()."</div>";
					
					while( $e = $Day->getEntry() ){
						//var_dump($e);
						$html .= "\n\t<p>".$e['entry']."</p>";
					}
					$html .= "</td>\n";
					
				}else{
			
					$html .= '<td width="50px">'.$Day->thisDay()."</td>\n";
				}//end selected
				
			}
		
			if ($Day->isLast()) {
				$html .= "</tr>\n";
			}
		}//edn foreach
		return $html;
	
	}//end table
	
	
}//end class

?>
